package br.edu.fanor.gema.ejb.dao.morphia;

import java.util.ArrayList;
import java.util.List;


public class GenericDAO<T> { //extends BasicDAO<T, ObjectId> {
	MorphiaConn conn;
	
	public GenericDAO() {
//		super();
		conn = new MorphiaConn();
		
	}

//	public List<T> listaTodos() {
//		return conn.getDatastore().find(Class<T>).asList();
//	}

	public void apagar(T object) {
		conn.getDatastore().delete(object);
	}
	
	public void atualizar(T object) {
		conn.getDatastore().delete(object);
	}

	public void salvar(T p) {
		conn.getDatastore().save(p);
	}
	
	/**
	 * Returns a list of Ts sharing folders to the specified T.
	 * TODO: implement this
	 * @param T the T
	 * @return the list of Ts sharing files to selected T
	 */
	public List<T> getTsSharingFoldersForT(T object) {
		//      return manager.createQuery("select distinct f.owner from Folder f " +
		//                              "LEFT JOIN f.permissions p where f.owner.id != :TId and f.deleted=false " +
		//                              "and (p.T.id=:TId or p.group.id in (select distinct gg.id " +
		//                              "from Group gg join gg.members memb where memb.id=:TId))) ").
		//                              setParameter("TId", TId).getResultList();
		return new ArrayList<T>();
	}

	/**
	 * Returns a list of Ts sharing files to specified T
	 * TODO: implement this
	 * @param T the T
	 * @return the list of Ts sharing files to selected T
	 */
	public List<T> getTsSharingFilesForT(T T) {
		//      List<T> Ts = manager.createQuery("select distinct f.owner from FileHeader f " +
		//                              "LEFT JOIN f.permissions p where f.owner.id != :TId and f.deleted=false " +
		//                              "and (p.T.id=:TId or p.group.id in (select distinct gg.id from Group gg " +
		//                              "join gg.members memb where memb.id=:TId)))").
		//                              setParameter("TId", TId).getResultList();
		//      return Ts;
		return new ArrayList<T>();
	}


}
